package com.fare.taluo.application.impl.analyse;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.collections.ListUtils;
import org.apache.hadoop.hbase.filter.Filter;

import com.fare.taluo.util.DateUtils;
import com.fare.taluo.vo.core.PlaneInfo;

/**
 * @author spring.华 
 * 	e-mail 13719279477@139.com
 */
public enum PriceSearchChoseEnum {

	M{//上午
		public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,List<Filter> filters) throws Exception{
			return this.implPlaneChoseData(dates,rowKeyHead,"08","12", filters);
		}
	},
	B{//中午
		public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,List<Filter> filters) throws Exception{
			return this.implPlaneChoseData(dates,rowKeyHead,"12","14", filters);
		}
	},
	A{//下午
		public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,List<Filter> filters) throws Exception{
			return this.implPlaneChoseData(dates,rowKeyHead,"14","18", filters);
		}
	},
	N{//nihgt
		public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,List<Filter> filters) throws Exception{
			List<PlaneInfo> list1=this.implPlaneChoseData(dates,rowKeyHead,"18","24", filters);
			List<PlaneInfo> list2=this.implPlaneChoseData(dates,rowKeyHead,"00","08", filters);
			return ListUtils.sum(list1, list2);//合并
		}
	},
	P{//自定义时间
		public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,String timeBegin,String timeEnd,List<Filter> filters)throws Exception{
				return this.implPlaneChoseData(dates,rowKeyHead,timeBegin,timeEnd, filters);
		}
	}
	;
	
	public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,List<Filter> filters)throws Exception{
		
		return null;
	}
	public List<PlaneInfo> getPlaneInfos(String dates,String rowKeyHead,String timeBegin,String timeEnd,List<Filter> filters)throws Exception{
		
		return null;
	}
	
	@SuppressWarnings({ "unused", "rawtypes", "unchecked" })
	protected  List<PlaneInfo>  implPlaneChoseData(String date,String rowKeyHead,String beginTime,String endTime,List<Filter> filters) throws Exception{
		String START_FLIGHT_NO = "000000000000000000000000";
		   String END_FLIGHT_NO = "ZZZZZZZZZZZZZZZZZZZZZZZZ";
		PriceSearchApplicationImpl impl=new PriceSearchApplicationImpl(); 
		List<List<PlaneInfo>>  dataList=new ArrayList();
		if(rowKeyHead.indexOf("&")!=-1)	{
			String[] info = rowKeyHead.split("_");
			String tableName = info[1];
			String rowHead = info[0];
			if("LP_FLIGHT_DATE".equals(tableName)){
				if(beginTime.equals("00")){//晚上零时加一天
					
					dataList.add(impl.searchByContidions(tableName,rowHead+DateUtils.getNextDateByDateStr(date, "yyyyMMdd")+START_FLIGHT_NO,
							rowHead+DateUtils.getNextDateByDateStr(date, "yyyyMMdd")+END_FLIGHT_NO,filters));
				}else{
					dataList.add(impl.searchByContidions(tableName,rowHead+date+START_FLIGHT_NO,rowHead+date+END_FLIGHT_NO,filters));
				}
				
			}else if("LP_FLIGHT_HISTORY_DOUBLE".equals(tableName)){
				
				if(beginTime.equals("00")){//晚上零时加一天
					rowHead = rowHead.replace("#", DateUtils.getNextDateByDateStr(date, "yyyyMMdd"));
					dataList.add(impl.searchByContidions(tableName,rowHead+"00000000",
							rowHead+"ZZZZZZZZ",filters));
				}else{
					rowHead = rowHead.replace("#", date);
					dataList.add(impl.searchByContidions(tableName,rowHead+"00000000",rowHead+"ZZZZZZZZ",filters));
				}
			}			
		}else{
			//原来代码
			if(beginTime.equals("00")){//晚上零时加一天
				dataList.add(impl.search(rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyyMMdd")+beginTime+"00000000",
						rowKeyHead+DateUtils.getNextDateByDateStr(date, "yyyyMMdd")+endTime+"00000000",filters));
			}else{
				dataList.add(impl.search(rowKeyHead+date+beginTime+"00000000",rowKeyHead+date+endTime+"00000000",filters));
			}
		
		}
		
		
			
		List<PlaneInfo> list=new ArrayList<PlaneInfo>();
		for (Iterator iterator = dataList.iterator(); iterator.hasNext();) {
			List<PlaneInfo> pls = (List<PlaneInfo>) iterator.next();
			for (Iterator iterator2 = pls.iterator(); iterator2.hasNext();) {
				PlaneInfo planeInfo = (PlaneInfo) iterator2.next();
				if(planeInfo!=null){
					list.add(planeInfo);
				}
			}
			
		}
		return list;
		
	}
	
}
